package labox.innovation.gameserver.pathfinding;

import labox.innovation.gameserver.geodata.GeoData;

/**
 *
 * @author -Nemesiss-
 */
public class Node {
	
	final AbstractNodeLoc _loc;

	private final GeoData _geo;

	Node _parent;

	int g;
	
	int h;
	
	int f;

	public Node(AbstractNodeLoc Loc, GeoData geo) {
		_loc = Loc;
		_geo = geo;
	}

	public void setParent(Node p) {
		_parent = p;
	}

	public void setCost(int cost) {
		f = (short) cost;
	}

	public Node[] getNeighbors() {
		if (_loc == null)
			return null;
		else
			return PathFinding.getInstance().readNeighbors(this, _geo);
	}

	public Node getParent() {
		return _parent;
	}

	public AbstractNodeLoc getLoc() {
		return _loc;
	}

	public int getCost() {
		return f;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((_loc == null) ? 0 : _loc.hashCode());
		return result;
	}

	public boolean equals(Node obj) {
		return _loc.equals(obj._loc);
	}
	
	public String toString(){
		return  "( NodeX:"+_loc.getNodeX()+" NodeY:"+_loc.getNodeY()+")";
	}

}
